// pages/photoguifan/photoguifan.js
Page({

  data: {     goods_id:'',near_id:'',type:'',show:false

  },

  onLoad: function (options) {
    console.log(options);
    
      this.setData({
        goods_id:options.goods_id,
        near_id:options.near_id,
        type:options.type
      })
  },
   paizhao(){
     this.setData({show:true})
    wx.chooseImage({
      count:1,
      success: (res) => {
        console.log(res);
        wx.showLoading({
          title: '正在识别中',
          mask:true
        })
        wx.uploadFile({
          filePath: res.tempFiles[0].path,
          name: 'file',
          url: 'https://zujieba.com/Api/upload/upload.html',
          success:(res1)=>{
          
            console.log(res1);
            let data=JSON.parse(res1.data)
          /*  wx.request({
             url: 'https://zujieba.com/Api/upload/baidu_file.html',
             data:{file:data.name,color:'255,255,255'},
             method:'POST',
             success:(res2)=>{
               console.log(res2);
               let url="https://zujieba.com/uploads/"+res2.data.url
               console.log(url);
               wx.navigateTo({
                 url:"/pages/yicuncanvas/yicuncanvas?type="+this.data.type+"&near_id="+this.data.near_id+'&goods_id='+this.data.goods_id+"&url="+url+'&baseurl='+res2.data.url+"&file="+data.name,
               })
               wx.hideLoading()
               
             }
           })*/
           wx.request({
            url: 'https://zujieba.com/Api/upload/baidu_koutu.html',
            data:{file:data.name},
            method:'POST',
            success:(res)=>{
              console.log(res);
              let data1=res.data.data
               wx.request({
                 url: 'https://zujieba.com/Api/upload/baidu_color.html',
                 data:{color:'255,0,0',file:data1},
                 method:"POST",
                 success:(res3)=>{
                 if(res3.data.success==1){
                  this.setData({show:false})
                  console.log(res3);
                  let url="https://zujieba.com/uploads/"+res3.data.data
                  console.log(url);
                  wx.navigateTo({
                    url:"/pages/yicuncanvas/yicuncanvas?type="+this.data.type+"&near_id="+this.data.near_id+'&goods_id='+this.data.goods_id+"&url="+url+'&baseurl='+res3.data.data+"&file="+data1,
                  })
                  wx.hideLoading()
                 }else{
                   wx.showToast({
                     title:res3.data.tips
                   })
                 }
                 },
                 fail:(res)=>{
                   wx.showToast({
                     title:"上传失败",
                     icon:'none'
                   })
                 }
               })
            }
           })
          }
        })
        
      
      },
      fail:(res)=>{
        this.setData({show:false})
      
      },
      complete:(res)=>{
        
      }
    })
   
   },
   paizhao1(){
      wx.chooseImage({
        count:1,
        success: (res) => {
          console.log(res);
          
          wx.navigateTo({
            url: '/pages/edit6/edit6?near_id='+this.data.near_id+"&goods_id="+this.data.goods_id+'&type='+this.data.type+'&url='+res.tempFiles[0].path,
          })
        },
      })
   }
})